<?php
	class Mcategory extends CI_Model{
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function list_main_category()
		{
			$result=$this->db->query("SELECT c.id,c.nameVN,c.id_parent,c.pos FROM category c WHERE c.id_parent=0 ORDER BY c.pos ");
			return $result->result_array();
		}
		public function main_category($cid)
		{
			$result=$this->db->query("SELECT c.id,c.nameVN,c.id_parent,c.pos FROM category c WHERE c.id='$cid' ORDER BY c.pos ");
			return $result->result_array();
		}
		public function list_category_detail($cid)
		{
			$result=$this->db->query("SELECT c.id,c.nameVN,c.id_parent,c.pos FROM category c WHERE c.id_parent='$cid' ORDER BY c.pos ");
			return $result->result_array();
		}
		public function list_category()
		{
			$result=$this->db->query("SELECT c.id,c.nameVN,c.id_parent,c.pos FROM category c ORDER BY c.pos ");
			return $result->result_array();
		}
		public function add_category_detail($pos,$nameVN,$cid)
		{
			$result=$this->db->query("INSERT INTO `category` (`nameVN`, `pos`,`id_parent`) VALUES ('$nameVN', '$pos', '$cid')");
			//return $result->result_array();
		}
		public function edit_category_detail($pos,$nameVN,$id_category,$parent)
		{
			$result=$this->db->query("UPDATE `category` SET `nameVN`='$nameVN', `pos`='$pos', `id_parent`='$parent' WHERE (`id`='$id_category')");
			//return $result->result_array();
		}
		public function delcategory($cid)
		{
			$result=$this->db->query("DELETE FROM `category` WHERE (`id`='$cid')");
			//return $result->result_array();
		}
		public function add_main_category($pos,$nameVN)
		{
			$result=$this->db->query("INSERT INTO `category` (`nameVN`, `pos`) VALUES ('$nameVN', '$pos')");
			//return $result->result_array();
		}
		public function edit_main_category($pos,$nameVN,$id_category)
		{
			$result=$this->db->query("UPDATE `category` SET `nameVN`='$nameVN', `pos`='$pos' WHERE (`id`='$id_category')");
			//return $result->result_array();
		}
	}
?>